<template>
    <div id="login">

        <div id="loginBox">
            <el-form :model="loginForm" status-icon :rules="loginRules" ref="ruleForm"  label-width="80px" class="demo-ruleForm" id="loginForm">
                <el-form-item label="账号:" prop="username">
                    <el-input type="text" v-model="loginForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码:" prop="password">
                    <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login()" style="background-color: black" >提交</el-button>
                    <el-button style="background-color: #ff0000" >重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
    
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                //登录的表单对象
                loginForm:{},
                //登录的规则
                loginRules:{
                    username:[
                        { required: true, message: '请输入账号', trigger: 'blur' },
                    ],
                    password:[
                        { required: true, message: '请输入密码', trigger: 'blur' },
                    ]
                }
            }
        },
        methods:{
            login(){
                this.$http.post("http://localhost:8001/login",this.loginForm).then(result=>{
                    if(result.data.code===200){
                        localStorage.setItem("token",result.data.data);
                        this.$router.push("/user")
                    }else{
                        this.$message.errorr("登录失败")
                    }
                })
            }
        }
    }
</script>

<style scoped>
    #loginBox{
        width: 400px;
        height: 550px;
        margin:200px auto;


    }
    #loginForm{
        margin: 20px auto;
    }
    .el-button{
        margin: 1px auto;
    }
    #login{
        width: 550px;
        height: 550px;
        margin: 1px auto;
        line-height: 200px;
    }
    body{
        /*background-image:-webkit-linear-gradient(bottom,#9e9494, #000000,#9e9494 );*/
        background-image:-webkit-linear-gradient(bottom, rgb(0, 0, 0), rgb(255, 255, 255), rgb(0, 0, 0));

    }
</style>